60. Araxis Merge File Comparison Report

Produced by Araxis Merge on 2023-03-13 03:00:43 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

60.1 Files compared

#LocationFileLast Modified
1Porto v4.0.4/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2022-04-22 07:34:10 +0000
2Porto v4.0.5/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/FilterCategory.php2022-12-08 01:34:28 +0000

60.2 Comparison summary

DescriptionBetween
Files 1 and 2
Text BlocksLines
Unchanged4862
Changed27
Inserted14
Removed00

60.3 Comparison options

WhitespaceConsecutive whitespace is treated as a single space
Character caseDifferences in character case are significant
Line endingsDifferences in line endings (CR and LF characters) are ignored
CR/LF charactersNot shown in the comparison detail
Active line-pairing rules

60.4 Active regular expressions

No regular expressions were active.

60.5 Comparison detail

1 <?php 1 <?php
2 /** 2 /**
3  * Mageplaza 3  * Mageplaza
4  * 4  *
5  * NOTICE OF LICENSE 5  * NOTICE OF LICENSE
6  * 6  *
7  * This source file is subject to the Mageplaza.com license that is 7  * This source file is subject to the Mageplaza.com license that is
8  * available through the world-wide-web at this URL: 8  * available through the world-wide-web at this URL:
9  * https://www.mageplaza.com/LICENSE.txt 9  * https://www.mageplaza.com/LICENSE.txt
10  * 10  *
11  * DISCLAIMER 11  * DISCLAIMER
12  * 12  *
13  * Do not edit or add to this file if you wish to upgrade this extension to newer 13  * Do not edit or add to this file if you wish to upgrade this extension to newer
14  * version in the future. 14  * version in the future.
15  * 15  *
16  * @category    Mageplaza 16  * @category    Mageplaza
17  * @package     Mageplaza_LayeredNavigation 17  * @package     Mageplaza_LayeredNavigation
18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/) 18  * @copyright   Copyright (c) Mageplaza (https://www.mageplaza.com/)
19  * @license     https://www.mageplaza.com/LICENSE.txt 19  * @license     https://www.mageplaza.com/LICENSE.txt
20  */ 20  */
21  21 
22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; 22 namespace Mageplaza\LayeredNavigation\Model\Layer\Filter;
23  23 
24 use Magento\Catalog\Api\CategoryManagementInterface; 24 use Magento\Catalog\Api\CategoryManagementInterface;
25 use Magento\Catalog\Api\Data\CategoryTreeInterface; 25 use Magento\Catalog\Api\Data\CategoryTreeInterface;
26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface; 26 use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
27 use Magento\Catalog\Model\Layer as LayerCatalog; 27 use Magento\Catalog\Model\Layer as LayerCatalog;
28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory; 28 use Magento\Catalog\Model\Layer\Filter\DataProvider\CategoryFactory;
29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; 29 use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder;
30 use Magento\Catalog\Model\Layer\Filter\ItemFactory; 30 use Magento\Catalog\Model\Layer\Filter\ItemFactory;
31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute; 31 use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter; 32 use Magento\CatalogSearch\Model\Layer\Filter\Category as AbstractFilter;
33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection; 33 use Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection;
34 use Magento\Framework\App\RequestInterface; 34 use Magento\Framework\App\RequestInterface;
35 use Magento\Framework\Escaper; 35 use Magento\Framework\Escaper;
36 use Magento\Framework\Exception\LocalizedException; 36 use Magento\Framework\Exception\LocalizedException;
37 use Magento\Framework\Exception\NoSuchEntityException; 37 use Magento\Framework\Exception\NoSuchEntityException;
38 use Magento\Framework\Exception\StateException; 38 use Magento\Framework\Exception\StateException;
39 use Magento\Store\Model\StoreManagerInterface; 39 use Magento\Store\Model\StoreManagerInterface;
40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; 40 use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper;
41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel; 41 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\CategoriesLevel;
42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree; 42 use Mageplaza\LayeredNavigation\Model\Category\Attribute\Source\RenderCategoryTree;
43  43 
44 /** 44 /**
45  * Class Category 45  * Class Category
46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter 46  * @package Mageplaza\LayeredNavigation\Model\Layer\Filter
47  */ 47  */
48 class Category extends AbstractFilter 48 class Category extends AbstractFilter
49 { 49 {
50     /** @var LayerHelper */ 50     /** @var LayerHelper */
51     protected $_moduleHelper; 51     protected $_moduleHelper;
52  52 
53     /** @var bool Is Filterable Flag */ 53     /** @var bool Is Filterable Flag */
54     protected $_isFilter = false; 54     protected $_isFilter = false;
55  55 
56     /** @var Escaper */ 56     /** @var Escaper */
57     private $escaper; 57     private $escaper;
58  58 
59     /** @var  LayerCatalog\Filter\DataProvider\Category */ 59     /** @var  LayerCatalog\Filter\DataProvider\Category */
60     private $dataProvider; 60     private $dataProvider;
61     /** 61     /**
62      * @var ProductAttributeRepositoryInterface 62      * @var ProductAttributeRepositoryInterface
63      */ 63      */
64     protected $attributeRepository; 64     protected $attributeRepository;
65     /** 65     /**
66      * @var CategoryManagementInterface 66      * @var CategoryManagementInterface
67      */ 67      */
68     protected $categoryManagement; 68     protected $categoryManagement;
69  69 
70     /** 70     /**
71      * @var Attribute 71      * @var Attribute
72      */ 72      */
73     protected $attributeData; 73     protected $attributeData;
74  74 
75     protected $isFullCategoryTree = false; 75     protected $isFullCategoryTree = false;
76     /** 76     /**
77      * @var Item\DataBuilder 77      * @var Item\DataBuilder
78      */ 78      */
79     protected $layerDataBuilder; 79     protected $layerDataBuilder;
80     /** 80     /**
81      * @var CategoryItemFactory 81      * @var CategoryItemFactory
82      */ 82      */
83     protected $categoryItemFactory; 83     protected $categoryItemFactory;
84  84 
85     /** 85     /**
86      * Category constructor. 86      * Category constructor.
87      * 87      *
88      * @param ItemFactory $filterItemFactory 88      * @param ItemFactory $filterItemFactory
89      * @param StoreManagerInterface $storeManager 89      * @param StoreManagerInterface $storeManager
90      * @param LayerCatalog $layer 90      * @param LayerCatalog $layer
91      * @param DataBuilder $itemDataBuilder 91      * @param DataBuilder $itemDataBuilder
92      * @param Escaper $escaper 92      * @param Escaper $escaper
93      * @param CategoryFactory $dataProviderFactory 93      * @param CategoryFactory $dataProviderFactory
94      * @param LayerHelper $moduleHelper 94      * @param LayerHelper $moduleHelper
95      * @param ProductAttributeRepositoryInterface $attributeRepository 95      * @param ProductAttributeRepositoryInterface $attributeRepository
96      * @param CategoryManagementInterface $categoryManagement 96      * @param CategoryManagementInterface $categoryManagement
97      * @param Item\DataBuilder $layerDataBuilder 97      * @param Item\DataBuilder $layerDataBuilder
98      * @param CategoryItemFactory $categoryItemFactory 98      * @param CategoryItemFactory $categoryItemFactory
99      * @param array $data 99      * @param array $data
100      * 100      *
101      * @throws LocalizedException 101      * @throws LocalizedException
102      */ 102      */
103     public function __construct( 103     public function __construct(
104         ItemFactory $filterItemFactory, 104         ItemFactory $filterItemFactory,
105         StoreManagerInterface $storeManager, 105         StoreManagerInterface $storeManager,
106         LayerCatalog $layer, 106         LayerCatalog $layer,
107         DataBuilder $itemDataBuilder, 107         DataBuilder $itemDataBuilder,
108         Escaper $escaper, 108         Escaper $escaper,
109         CategoryFactory $dataProviderFactory, 109         CategoryFactory $dataProviderFactory,
110         LayerHelper $moduleHelper, 110         LayerHelper $moduleHelper,
111         ProductAttributeRepositoryInterface $attributeRepository, 111         ProductAttributeRepositoryInterface $attributeRepository,
112         CategoryManagementInterface $categoryManagement, 112         CategoryManagementInterface $categoryManagement,
113         Item\DataBuilder $layerDataBuilder, 113         Item\DataBuilder $layerDataBuilder,
114         CategoryItemFactory $categoryItemFactory, 114         CategoryItemFactory $categoryItemFactory,
115         array $data = [] 115         array $data = []
116     ) { 116     ) {
117         parent::__construct( 117         parent::__construct(
118             $filterItemFactory, 118             $filterItemFactory,
119             $storeManager, 119             $storeManager,
120             $layer, 120             $layer,
121             $itemDataBuilder, 121             $itemDataBuilder,
122             $escaper, 122             $escaper,
123             $dataProviderFactory, 123             $dataProviderFactory,
124             $data 124             $data
125         ); 125         );
126  126 
127         $this->escaper             = $escaper; 127         $this->escaper             = $escaper;
128         $this->_moduleHelper       = $moduleHelper; 128         $this->_moduleHelper       = $moduleHelper;
129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]); 129         $this->dataProvider        = $dataProviderFactory->create(['layer' => $this->getLayer()]);
130         $this->attributeRepository = $attributeRepository; 130         $this->attributeRepository = $attributeRepository;
131         $this->categoryManagement  = $categoryManagement; 131         $this->categoryManagement  = $categoryManagement;
132         $this->layerDataBuilder    = $layerDataBuilder; 132         $this->layerDataBuilder    = $layerDataBuilder;
133         $this->categoryItemFactory = $categoryItemFactory; 133         $this->categoryItemFactory = $categoryItemFactory;
134     } 134     }
135  135 
136     /** 136     /**
137      * @inheritdoc 137      * @inheritdoc
138      */ 138      */
139     public function apply(RequestInterface $request) 139     public function apply(RequestInterface $request)
140     { 140     {
141         if (!$this->_moduleHelper->isEnabled()) { 141         if (!$this->_moduleHelper->isEnabled()) {
142             return parent::apply($request); 142             return parent::apply($request);
143         } 143         }
144  144 
145         $categoryId = $request->getParam($this->_requestVar); 145         $categoryId = $request->getParam($this->_requestVar);
146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree)
{
 146         if (empty($categoryId) && $this->isRenderCategoryTree() && $this->isFullCategoryTree) {
147             $request->setParam($this->_requestVar,
$this->dataProvider->getCategory()->getId());
 147             $request->setParam($this->_requestVar, $this->dataProvider->getCategory()->getId());
148             $categoryId = $request->getParam($this->_requestVar); 148             $categoryId = $request->getParam($this->_requestVar);
149         } 149         }
150         if (empty($categoryId)) { 150         if (empty($categoryId)) {
151             return $this; 151             return $this;
152         } 152         }
153  153 
154         $categoryIds = []; 154         $categoryIds = [];
155         $categoryId = explode(',', $categoryId); $categoryId = array_unique($categoryId); 155         $categoryId = explode(',', $categoryId);
    156         $categoryId = array_unique($categoryId);
156         foreach ($categoryId as $id) { 157         foreach ($categoryId as $id) {
157             $this->dataProvider->setCategoryId($id); 158             $this->dataProvider->setCategoryId($id);
158             if ($this->dataProvider->isValid()) { 159             if ($this->dataProvider->isValid()) {
159                 $category = $this->dataProvider->getCategory(); 160                 $category = $this->dataProvider->getCategory();
160                 if ($this->isRenderCategoryTree()) { 161                 if ($this->isRenderCategoryTree()) {
161                     $categoryIds[] = $id; 162                     $categoryIds[] = $id;
162                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 163                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
163                 } elseif ($request->getParam('id') !== $id) { 164                 } elseif ($request->getParam('id') !== $id) {
164                     $categoryIds[] = $id; 165                     $categoryIds[] = $id;
165                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id)); 166                     $this->getLayer()->getState()->addFilter($this->_createItem($category->getName(), $id));
166                 } 167                 }
167             } 168             }
168         } 169         }
169  170 
170         if (!empty($categoryIds)) { 171         if (!empty($categoryIds)) {
171             $this->_isFilter = true; 172             $this->_isFilter = true;
172             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) { 173             if ($this->isRenderCategoryTree() && $this->isFullCategoryTree) {
173                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId()) 174                 $this->getLayer()->getProductCollection()->resetCategoryIds($this->getCurrentCategoryId())
174                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds); 175                     ->resetCategoryFilter($this->getCurrentCategoryId())->addLayerCategoryFilter($categoryIds);
175             } else { 176             } else {
176                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds); 177                 $this->getLayer()->getProductCollection()->addLayerCategoryFilter($categoryIds);
177             } 178             }
178         } 179         }
179  180 
180         if ($parentCategoryId = $request->getParam('id')) { 181         if ($parentCategoryId = $request->getParam('id')) {
181             $this->dataProvider->setCategoryId($parentCategoryId); 182             $this->dataProvider->setCategoryId($parentCategoryId);
182         } 183         }
183  184 
184         return $this; 185         return $this;
185     } 186     }
186  187 
187     /** 188     /**
188      * @inheritDoc 189      * @inheritDoc
189      */ 190      */
190     protected function _initItems() 191     protected function _initItems()
191     { 192     {
    193         if (!$this->_moduleHelper->isEnabled()) {
    194             return parent::_initItems();
    195         }
    196 
192         if ($this->isRenderCategoryTree()) { 197         if ($this->isRenderCategoryTree()) {
193             $data = $this->getCategoryAdditionData(); 198             $data = $this->getCategoryAdditionData();
194             /** @var CategoryItem $itemCollection */ 199             /** @var CategoryItem $itemCollection */
195             $itemCollection = $this->categoryItemFactory->create(); 200             $itemCollection = $this->categoryItemFactory->create();
196             if ($data && $data['count']) { 201             if ($data && $data['count']) {
197                 $itemCollection->setStartPath($data['startPath']); 202                 $itemCollection->setStartPath($data['startPath']);
198                 $itemCollection->setCount($data['count']); 203                 $itemCollection->setCount($data['count']);
199                 foreach ($data['items'] as $parentId => $items) { 204                 foreach ($data['items'] as $parentId => $items) {
200                     foreach ($items as $item) { 205                     foreach ($items as $item) {
201                         $itemCollection->addItem( 206                         $itemCollection->addItem(
202                             $item['parent_id'], 207                             $item['parent_id'],
203                             $this->_createItem($item['label'], $item['value'], $item['count']) 208                             $this->_createItem($item['label'], $item['value'], $item['count'])
204                         ); 209                         );
205                     } 210                     }
206                 } 211                 }
207             } 212             }
208  213 
209             $this->_items = $itemCollection; 214             $this->_items = $itemCollection;
210  215 
211             return $this; 216             return $this;
212         } 217         }
213  218 
214         return parent::_initItems(); 219         return parent::_initItems();
215     } 220     }
216  221 
217     /** 222     /**
218      * @return array 223      * @return array
219      * @throws StateException 224      * @throws StateException
220      */ 225      */
221     protected function _getItemsData() 226     protected function _getItemsData()
222     { 227     {
223         if (!$this->_moduleHelper->isEnabled()) { 228         if (!$this->_moduleHelper->isEnabled()) {
224             return parent::_getItemsData(); 229             return parent::_getItemsData();
225         } 230         }
226  231 
227         /** @var Collection $productCollection */ 232         /** @var Collection $productCollection */
228         $productCollection = $this->getLayer()->getProductCollection(); 233         $productCollection = $this->getLayer()->getProductCollection();
229  234 
230         if ($this->_isFilter) { 235         if ($this->_isFilter) {
231             $productCollection = $productCollection->getCollectionClone() 236             $productCollection = $productCollection->getCollectionClone()
232                 ->removeAttributeSearch('category_ids'); 237                 ->removeAttributeSearch('category_ids');
233         } 238         }
234  239 
235         $optionsFacetedData = $productCollection->getFacetedData('category'); 240         $optionsFacetedData = $productCollection->getFacetedData('category');
236         $category           = $this->dataProvider->getCategory(); 241         $category           = $this->dataProvider->getCategory();
237         $categories         = $category->getChildrenCategories(); 242         $categories         = $category->getChildrenCategories();
238  243 
239         $collectionSize = $productCollection->getSize(); 244         $collectionSize = $productCollection->getSize();
240  245 
241         if ($category->getIsActive()) { 246         if ($category->getIsActive()) {
242             foreach ($categories as $childCategory) { 247             foreach ($categories as $childCategory) {
243                 $count = isset($optionsFacetedData[$childCategory->getId()]) 248                 $count = isset($optionsFacetedData[$childCategory->getId()])
244                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0; 249                     ? $optionsFacetedData[$childCategory->getId()]['count'] : 0;
245                 if ($childCategory->getIsActive() 250                 if ($childCategory->getIsActive()
246                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize) 251                     && $this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $collectionSize)
247                 ) { 252                 ) {
248                     $this->itemDataBuilder->addItemData( 253                     $this->itemDataBuilder->addItemData(
249                         $this->escaper->escapeHtml($childCategory->getName()), 254                         $this->escaper->escapeHtml($childCategory->getName()),
250                         $childCategory->getId(), 255                         $childCategory->getId(),
251                         $count 256                         $count
252                     ); 257                     );
253                 } 258                 }
254             } 259             }
255         } 260         }
256  261 
257         return $this->itemDataBuilder->build(); 262         return $this->itemDataBuilder->build();
258     } 263     }
259  264 
260     /** 265     /**
261      * @return array 266      * @return array
262      * @throws LocalizedException 267      * @throws LocalizedException
263      * @throws NoSuchEntityException 268      * @throws NoSuchEntityException
264      */ 269      */
265     protected function getCategoryAdditionData() 270     protected function getCategoryAdditionData()
266     { 271     {
267         $attributeModel     = $this->getCategoryAttributeModel(); 272         $attributeModel     = $this->getCategoryAttributeModel();
268         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 273         $renderCategoryTree = $attributeModel->getData('render_category_tree');
269         $itemsData          = []; 274         $itemsData          = [];
270         $startPath          = ''; 275         $startPath          = '';
271  276 
272         try { 277         try {
273             $optionsFacetedData = $this->getFacetedData(); 278             $optionsFacetedData = $this->getFacetedData();
274             if (empty($optionsFacetedData)) { 279             if (empty($optionsFacetedData)) {
275                 $categoryId                      = $this->dataProvider->getCategory()->getId(); 280                 $categoryId                      = $this->dataProvider->getCategory()->getId();
276                 $optionsFacetedData[$categoryId] = [ 281                 $optionsFacetedData[$categoryId] = [
277                     'value' => $categoryId, 282                     'value' => $categoryId,
278                     'count' => $this->getLayer()->getProductCollection()->getSize() 283                     'count' => $this->getLayer()->getProductCollection()->getSize()
279                 ]; 284                 ];
280             } 285             }
281         } catch (StateException $e) { 286         } catch (StateException $e) {
282             return []; 287             return [];
283         } 288         }
284  289 
285         try { 290         try {
286             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY 291             $depth            = $renderCategoryTree !== RenderCategoryTree::FULL_CATEGORY
287                 ? $attributeModel->getData('category_tree_depth') 292                 ? $attributeModel->getData('category_tree_depth')
288                 : null; 293                 : null;
289             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth); 294             $categoryTreeList = $this->categoryManagement->getTree($this->getCurrentCategoryId(), $depth);
290         } catch (NoSuchEntityException $e) { 295         } catch (NoSuchEntityException $e) {
291             $categoryTreeList = []; 296             $categoryTreeList = [];
292         } 297         }
293  298 
294         if ($categoryTreeList) { 299         if ($categoryTreeList) {
295             if ($renderCategoryTree === RenderCategoryTree::CUSTOM 300             if ($renderCategoryTree === RenderCategoryTree::CUSTOM
296                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY 301                 && $attributeModel->getData('categories_level') === CategoriesLevel::CURRENT_CATEGORY
297             ) { 302             ) {
298                 $startPath = $categoryTreeList->getParentId(); 303                 $startPath = $categoryTreeList->getParentId();
299                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()]) 304                 $count     = isset($optionsFacetedData[$categoryTreeList->getId()])
300                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0; 305                     ? $optionsFacetedData[$categoryTreeList->getId()]['count'] : 0;
301  306 
302                 $this->layerDataBuilder->addItemData( 307                 $this->layerDataBuilder->addItemData(
303                     $this->escaper->escapeHtml($categoryTreeList->getName()), 308                     $this->escaper->escapeHtml($categoryTreeList->getName()),
304                     $categoryTreeList->getId(), 309                     $categoryTreeList->getId(),
305                     $categoryTreeList->getParentId(), 310                     $categoryTreeList->getParentId(),
306                     $categoryTreeList->getPosition(), 311                     $categoryTreeList->getPosition(),
307                     $categoryTreeList->getLevel(), 312                     $categoryTreeList->getLevel(),
308                     $count 313                     $count
309                 ); 314                 );
310             } else { 315             } else {
311                 $startPath = $categoryTreeList->getId(); 316                 $startPath = $categoryTreeList->getId();
312             } 317             }
313             $this->getCategoryTree($categoryTreeList, $optionsFacetedData); 318             $this->getCategoryTree($categoryTreeList, $optionsFacetedData);
314         } 319         }
315         $itemsData['startPath'] = $startPath; 320         $itemsData['startPath'] = $startPath;
316         $itemsData['count']     = $this->layerDataBuilder->getCount(); 321         $itemsData['count']     = $this->layerDataBuilder->getCount();
317         $itemsData['items']     = $this->layerDataBuilder->build(); 322         $itemsData['items']     = $this->layerDataBuilder->build();
318  323 
319         return $itemsData; 324         return $itemsData;
320     } 325     }
321  326 
322     /** 327     /**
323      * @return bool 328      * @return bool
324      * @throws NoSuchEntityException 329      * @throws NoSuchEntityException
325      */ 330      */
326     public function isRenderCategoryTree() 331     public function isRenderCategoryTree()
327     { 332     {
328         $attributeModel     = $this->getCategoryAttributeModel(); 333         $attributeModel     = $this->getCategoryAttributeModel();
329         $renderCategoryTree = $attributeModel->getData('render_category_tree'); 334         $renderCategoryTree = $attributeModel->getData('render_category_tree');
330  335 
331         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) { 336         if ($renderCategoryTree === RenderCategoryTree::FULL_CATEGORY) {
332             $this->isFullCategoryTree = true; 337             $this->isFullCategoryTree = true;
333         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM 338         } elseif ($renderCategoryTree === RenderCategoryTree::CUSTOM
334             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) { 339             && $attributeModel->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY) {
335             $this->isFullCategoryTree = true; 340             $this->isFullCategoryTree = true;
336         } 341         }
337  342 
338         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO; 343         return $renderCategoryTree && $renderCategoryTree !== RenderCategoryTree::NO;
339     } 344     }
340  345 
341     /** 346     /**
342      * @param CategoryTreeInterface $tree 347      * @param CategoryTreeInterface $tree
343      * @param array $optionsFacetedData 348      * @param array $optionsFacetedData
344      */ 349      */
345     public function getCategoryTree($tree, $optionsFacetedData) 350     public function getCategoryTree($tree, $optionsFacetedData)
346     { 351     {
347         if (!$tree) { 352         if (!$tree) {
348             return; 353             return;
349         } 354         }
350  355 
351         foreach ($tree->getChildrenData() as $item) { 356         foreach ($tree->getChildrenData() as $item) {
352             $count = isset($optionsFacetedData[$item->getId()]) 357             $count = isset($optionsFacetedData[$item->getId()])
353                 ? $optionsFacetedData[$item->getId()]['count'] : 0; 358                 ? $optionsFacetedData[$item->getId()]['count'] : 0;
354  359 
355             if ($item->getIsActive() === '1') { 360             if ($item->getIsActive() === '1') {
356                 $child = $item->getChildrenData(); 361                 $child = $item->getChildrenData();
357                 if ($item->getLevel() !== '1') { 362                 if ($item->getLevel() !== '1') {
358                     $this->layerDataBuilder->addItemData( 363                     $this->layerDataBuilder->addItemData(
359                         $this->escaper->escapeHtml($item->getName()), 364                         $this->escaper->escapeHtml($item->getName()),
360                         $item->getId(), 365                         $item->getId(),
361                         $item->getParentId(), 366                         $item->getParentId(),
362                         $item->getPosition(), 367                         $item->getPosition(),
363                         $item->getLevel(), 368                         $item->getLevel(),
364                         $count 369                         $count
365                     ); 370                     );
366                 } 371                 }
367  372 
368                 if ($child) { 373                 if ($child) {
369                     $this->getCategoryTree($item, $optionsFacetedData); 374                     $this->getCategoryTree($item, $optionsFacetedData);
370                 } 375                 }
371             } 376             }
372         } 377         }
373     } 378     }
374  379 
375     /** 380     /**
376      * @return int|null 381      * @return int|null
377      * @throws LocalizedException 382      * @throws LocalizedException
378      * @throws NoSuchEntityException 383      * @throws NoSuchEntityException
379      */ 384      */
380     protected function getCurrentCategoryId() 385     protected function getCurrentCategoryId()
381     { 386     {
382         if ($this->isFullCategoryTree) { 387         if ($this->isFullCategoryTree) {
383             $categoryId = $this->_storeManager->getStore()->getRootCategoryId(); 388             $categoryId = $this->_storeManager->getStore()->getRootCategoryId();
384         } else { 389         } else {
385             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY 390             $categoryId = $this->getCategoryAttributeModel()->getData('categories_level') === CategoriesLevel::ROOT_CATEGORY
386                 ? $this->_storeManager->getStore()->getRootCategoryId() 391                 ? $this->_storeManager->getStore()->getRootCategoryId()
387                 : $this->dataProvider->getCategory()->getId(); 392                 : $this->dataProvider->getCategory()->getId();
388         } 393         }
389  394 
390         return $categoryId; 395         return $categoryId;
391     } 396     }
392  397 
393     /** 398     /**
394      * @return array 399      * @return array
395      * @throws LocalizedException 400      * @throws LocalizedException
396      * @throws NoSuchEntityException 401      * @throws NoSuchEntityException
397      * @throws StateException 402      * @throws StateException
398      */ 403      */
399     protected function getFacetedData() 404     protected function getFacetedData()
400     { 405     {
401         /** @var Collection $productCollection */ 406         /** @var Collection $productCollection */
402         $productCollection = $this->getLayer()->getProductCollection(); 407         $productCollection = $this->getLayer()->getProductCollection();
403  408 
404         if ($this->_isFilter) { 409         if ($this->_isFilter) {
405             $productCollection = $productCollection->getCollectionClone() 410             $productCollection = $productCollection->getCollectionClone()
406                 ->removeAttributeSearch('category_ids'); 411                 ->removeAttributeSearch('category_ids');
407         } else { 412         } else {
408             $productCollection = $productCollection->getCollectionClone() 413             $productCollection = $productCollection->getCollectionClone()
409                 ->setCategoryFilter($this->getCurrentCategoryId()); 414                 ->setCategoryFilter($this->getCurrentCategoryId());
410         } 415         }
411  416 
412         return $productCollection->getFacetedData('category'); 417         return $productCollection->getFacetedData('category');
413     } 418     }
414  419 
415     /** 420     /**
416      * @return Attribute 421      * @return Attribute
417      * @throws NoSuchEntityException 422      * @throws NoSuchEntityException
418      */ 423      */
419     public function getCategoryAttributeModel() 424     public function getCategoryAttributeModel()
420     { 425     {
421         if (!$this->attributeData) { 426         if (!$this->attributeData) {
422             /** @var Attribute $attribute */ 427             /** @var Attribute $attribute */
423             $this->attributeData = $this->attributeRepository->get('category_ids'); 428             $this->attributeData = $this->attributeRepository->get('category_ids');
424             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) { 429             if ($this->attributeData->getId() && $data = $this->attributeData->getAdditionalData()) {
425                 $additionalData = $this->_moduleHelper->unserialize($data); 430                 $additionalData = $this->_moduleHelper->unserialize($data);
426                 if (is_array($additionalData)) { 431                 if (is_array($additionalData)) {
427                     $this->attributeData->addData($additionalData); 432                     $this->attributeData->addData($additionalData);
428                 } 433                 }
429             } 434             }
430         } 435         }
431  436 
432         return $this->attributeData; 437         return $this->attributeData;
433     } 438     }
434 } 439 }